 
// chrome.commands.onCommand.addListener((command) => {
//     console.log(`Command "${command}" triggered`);
// });

// chrome.runtime.onMessage.addListener((
//     req,
//     sender,
//     sendRep
// ) => {
//     if (req.type == "MsgFromPage") {
//         sendRep({ type: "MsgFromPage", data: "ok" });
//     }else{
//         sendRep({ type: "MsgFromPage", data: req });
//     }
// })

// chrome.tabs.onCreated.addListener(function(tab) {
// // 处理新标签页的逻辑
// });



(function() {
    console.log('main.js', chrome.runtime.id);
    // chrome.runtime.sendMessage(chrome.runtime.id, {action:'getLocalStorage', key:'SETTING'}, (rep) => {
    //     console.log(rep);
    // });

    let iframeApp;

    document.body.addEventListener('keydown', e => {
        if(e.key == 'q' && e.ctrlKey){
            e.preventDefault();

            // 获取 HTML 文件在扩展中的 URL
            const htmlURL = chrome.runtime.getURL('/index.html?skin=only');
            openAppOnIframe(htmlURL);

            // 新标签页打开
            // chrome.tabs.create({url:htmlURL});
        }
    })
    
    const openAppOnIframe = (htmlURL) => {
        if(iframeApp){
            iframeApp = document.body.removeChild(iframeApp);
            iframeApp = null;
            return;
        }

        iframeApp = document.createElement('div');
        iframeApp.onclick = openAppOnIframe;
        
        iframeApp.id = 'jusouApp';
        iframeApp.style.width = '100%';
        iframeApp.style.height = '100%';
        iframeApp.style.zIndex = 9999;
        iframeApp.style.position = 'absolute';
        iframeApp.style.left = 0;
        iframeApp.style.top = 0;
        iframeApp.style.backgroundColor = '#00000033';

    

        const iframe = document.createElement('iframe');
        iframe.classList.add('jusou-iframeApp-dialog');
        iframe.width = '100%';
        iframe.height = '100%';
        iframe.style.border = 'none';
        iframe.src = htmlURL;

        iframe.style.width = '900px';
        iframe.style.height = '600px';
        iframe.style.transform = 'translate(-50%, -50%)';
        iframe.style.position = 'absolute';
        iframe.style.left = '50%';
        iframe.style.top = '50%';
        iframe.style.borderRadius = '10px';
        iframe.style.boxShadow = '0 0 0 4px rgb(30 128 255 / 20%), 0 0 20px rgb(0 0 0 / 15%)';

        document.body.appendChild(iframeApp);
        iframeApp.appendChild(iframe);
                
        return iframeApp;
    }
})()
